package com.wejoy.video.middle.station.data.util;

import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/**
 * 判断当前系统运行环境
 */
@Component
public class EnvUtil implements EnvironmentAware {
    /** 系统环境 */
    private static Environment environment;

    /**
     * 判断是否开发环境
     * @return
     */
    public static boolean isDev() {
        return isEnv("dev");
    }

    /**
     * 判断是否测试环境
     * @return
     */
    public static boolean isTest() {
        return isEnv("test");
    }

    /**
     * 判断是否生产环境
     * @return
     */
    public static boolean isProd() {
        return isEnv("prod");
    }

    /**
     * 判断是否激活某个profile
     * @param env
     * @return
     */
    private static boolean isEnv(String env) {
        return environment.getProperty("env").equalsIgnoreCase(env);
    }

    public static String getEnv() {
        return environment.getProperty("env");
    }

    @Override
    public void setEnvironment(Environment environment) {
        EnvUtil.environment = environment;
    }

    public static boolean isESEnable() {
        return true;
    }
}
